/*****************************************************************
**                                                             	**
**  Copyright (C) 2004 Amlogic,Inc.                            	**
**  All rights reserved                                        	**
**        Filename : LoadingWin_1080P.c /Project:AVOS		       **
**        Revision : 1.1                                       	**
**                                                             	**
*****************************************************************/
#include "../menu.h"
#include "LoadingWinEvent.h"

INT32S LoadingWinMsgProc_1080P(PHWND hwnd, INT32U msg_type, INT32S lpParam)
{
    switch( msg_type){
        case WM_SHOWWINDOW:
            return LoadingWinOnShow(hwnd, lpParam) ;
        case WM_HIDEWINDOW:
            return LoadingWinOnHide(hwnd, lpParam) ;
    }
    return 0 ;
}

void SetLoadingWinPalette_1080P(void)
{
    YUVENTRY mask_para[4] = {0,0,0,0xfff};
    AWSetAlphaMask(0,4, mask_para);
    YUVENTRY palette_para[16] = {0x8000 | 16392,0x8000 | 21176,0x8000 | 17752,0x8000 | 16392,17592,19496,19832,19656,19992,18104,17673,17817,15864,15721,15912,16344};
    AWSetPalette(0,16, palette_para);
    return ;
}

void SetLoadingWinPos_1080P(HWND* pControl, INT8U CurOsdSize)
{
    switch(CurOsdSize){
	 case OsdSize1080p:
            RECT WindowRect1080p = {0,0,1920,1080};
            pControl->winrect = WindowRect1080p;
            CREATEWINDOWPARAM WindowPara1080p = {1,{{0,0,1920,1080},    {0,0,0,0},{0,0,0,0},{0,0,0,0}},{PF_PALETTE_256,0,0,0},    SetLoadingWinPalette_1080P};
            AWSendMessage(pControl, WM_WINDOW_RESET_DRAW_AREA, (INT32S)&WindowPara1080p);
            break ;
    }//end of switch
    return;
}

HWND *CreateControlLoadingWin_1080P(HWND* pParent,INT8U CurOsdSize)
{
    HWND* pNewControl;
    switch(CurOsdSize){
	 case OsdSize1080p:
            CREATEWINDOWPARAM window_para1080p = {1,{{0,0,1920,1080},{0,0,0,0},{0,0,0,0},{0,0,0,0}},{PF_PALETTE_256,0,0,0},SetLoadingWinPalette_1080P};
            //Create Menu Window -- 1
            pNewControl = AWCreateWinControl("TWindow","LoadingWin_1080P",WS_OVERLAPPEDWINDOW,
		                      0,0,0,0,NULL, (INT32S)&window_para1080p,LoadingWinMsgProc_1080P) ;
            pNewControl->win_id = 0 ;
            break ;
    }//end of switch
            return pNewControl;
}

void SetLoadingPos_1080P(HWND* pControl, INT8U CurOsdSize)
{
    int iLoop;
    switch(CurOsdSize){
	 case OsdSize1080p:
            pControl->winrect.top = pControl->parent->winrect.top + 820;
            pControl->winrect.left = pControl->parent->winrect.left + 800;
            pControl->winrect.width = 283;
            pControl->winrect.height = 65;
            pControl->draw_info_num = 1;
            RECT DrawRect1080p[1] = {
            {pControl->winrect.left ,pControl->winrect.top,283,65},
            };
            for(iLoop=0; iLoop < 1; iLoop++)
                memcpy(&(pControl->draw_info[iLoop]), &DrawRect1080p[iLoop], sizeof(RECT));
            break ;
    }//end of switch
    return;
}

INT32S LoadingMsgProc_1080P(PHWND hwnd, INT32U msg_type, INT32S lpParam)
{
    switch( msg_type){
        case WM_PAINT:
            return LoadingOnPaint(hwnd, lpParam) ;
        default:
            return LoadingOnOtherEvent(hwnd, msg_type, lpParam) ;
    }
    return 0 ;
}

HWND *CreateControlLoading_1080P(HWND *pParent,INT8U CurOsdSize)
{
    //Create Control -- Loading
    HWND *pNewControl;
    switch(CurOsdSize){
	 case OsdSize1080p:
            pNewControl = AWCreateWinControl("TControl","Loading_1080P",(WS_CHILDWINDOW | WS_CHILDWINDOW),
		                      800,820,283,65,pParent,0,LoadingMsgProc_1080P) ;
            pNewControl->win_id = 1 ;
            pNewControl->draw_info_num = 1;
            pNewControl->draw_info = (PDRAWINFO)AVMem_umalloc(sizeof(DRAWINFO) * pNewControl->draw_info_num) ;
            DRAWINFO DrawDatas1080p[1] = {
                          {0,0,250,65,(INT32U)LOADING_STR,DT_RESOURCE_STRING_DATA}};
            memcpy(pNewControl->draw_info,DrawDatas1080p, sizeof(DRAWINFO) * pNewControl->draw_info_num) ;
            break ;
    }//end of switch
            return pNewControl;
}

HWND* CreateMenuLoadingWin_1080P(void)
{
    HWND *pNewControl ;
    TWINDOWS *pWin;
    HWND *pLoadingWin = CreateControlLoadingWin_1080P(NULL,CurrentOsdSize);
    SetLoadingWinPos_1080P(pLoadingWin,CurrentOsdSize);

    pNewControl= CreateControlLoading_1080P(pLoadingWin,CurrentOsdSize);
    SetLoadingPos_1080P(pNewControl,CurrentOsdSize);

    pWin = (TWINDOWS *)pLoadingWin;
    pWin->pFocusControl = AWFindWinCtrlByName("Loading");
    return pLoadingWin;
}

void WinResetLoadingWinControlsPos_1080P(HWND *pControl, INT8U CurOsdSize)
{
    switch(pControl->win_id){
        case 0://LoadingWin
            SetLoadingWinPos_1080P(pControl,CurOsdSize) ;
            break ;
        case 1://Loading
            SetLoadingPos_1080P(pControl,CurOsdSize) ;
            break ;
    }//end of switch
}
void WinResetLoadingWinPos_1080P(HWND *pControl, INT8U CurOsdSize)
{
    HWND *pChildControl;
    if(pControl == NULL)
        pControl = AWFindWinCtrlByName("LoadingWin_1080P");
    if(pControl == NULL) return ;

    WinResetLoadingWinControlsPos_1080P(pControl, CurOsdSize) ;
    pChildControl = pControl->children ;
    while(pChildControl != NULL){
    	WinResetLoadingWinPos_1080P(pChildControl, CurOsdSize) ;
    	pChildControl = pChildControl->siblings ;
	}
	return ;
}

